local tousui = fk.CreateSkill{
    name = "jinld__tousui",
    tags = { Skill.Compulsory }
}

Fk:loadTranslationTable{
    ["jinld__tousui"] = "透髓",
    [":jinld__tousui"] = "锁定技，当你使用伤害类牌指定与你势力不同的角色为唯一目标后，其需弃置一张与此牌花色不同的牌，否则其不可响应此牌。"..
    "当其他角色死亡后，若你为伤害来源，你移除此武将牌，令所有与你势力相同的角色均执行此次奖惩，然后你失去1点体力。",

    ["#jinld__tousui_discard"] = "透髓：弃置一张与 %arg 花色不同的牌，否则你不可响应此牌",

    ["$jinld__tousui1"] = "区区黄口孺帝，能有何作为？",
    ["$jinld__tousui2"] = "昔年沙场茹血，今欲饮帝血！",
}

local H = require "packages/ol_hegemony/util"

tousui:addEffect(fk.TargetSpecified,{
    anim_type = "offensive",
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasSkill(tousui.name) and not H.compareKingdomWith(player, data.to) and data:isOnlyTarget(data.to)
        and data.card.is_damage_card and not data.to:isNude()
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local to = data.to
        if player.dead or to.dead then return end
        local suits = {"spade", "club", "heart", "diamond"}
        table.remove(suits, data.card.suit)
        local card = room:askToCards(to,{
            min_num = 1,
            max_num = 1,
            pattern = ".|.|"..table.concat(suits, ","),
            prompt = "#jinld__tousui_discard:::"..data.card:toLogString(),
            skill_name = tousui.name,
            cancelable = true,
        })
        if #card > 0 then
            room:throwCard(card, tousui.name, to, to)
        else
            data:setDisresponsive(to)
        end
    end,
})

tousui:addEffect(fk.BuryVictim,{
    anim_type = "negative",
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(tousui.name) and data.damage.from == player
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local deathEvent = room.logic:getCurrentEvent():findParent(GameEvent.Death, true).data
        deathEvent.extra_data = deathEvent.extra_data or {}
        deathEvent.extra_data.jinld__tousui = true
        room:setPlayerMark(player, tousui.name, 1)
    end,
})

tousui:addEffect(fk.Deathed,{
    anim_type = "negative",
    is_delay_effect = true,
    can_trigger = function (self, event, target, player, data)
        return player:getMark(tousui.name) > 0 and player:hasSkill(tousui.name) and data.damage.from == player
    end,
    on_use = function (self, event, target, player, data)
        local isDeputy = H.inGeneralSkills(player, tousui.name)
        if isDeputy then
        H.removeGeneral(player, isDeputy == "d")
        end
        player.room:loseHp(player, 1, tousui.name)
    end,
})

return tousui